Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.getName = getName, exports.getVersions = getVersions, exports.VERSION = void 0;

var VERSION = {
    SINGLE_PAGE: 0,
    COMPANY_DISPLAY: 3,
    CPMPANY_SITE: 1,
    SERVICE_ORDER: 4,
    COMPANY_E_COMMERCE: 2,
    FULL_FEATURE: 5
};

exports.VERSION = VERSION;

var versions = [];

function setUpContents(e, t) {
    e.forEach(function(n) {
        if (n.contents = [], "单页展示型" === n.name ? n.contents.push(t[0][0]) : n.contents.push(t[0][1]), 
        n.models.forEach(function(e) {
            n.contents.push(t[e]);
        }), "全功能旗舰版" === n.name) {
            var e = t[0][2];
            e && (n.contents.length = 0, n.contents.push(e));
        }
        0 !== n.code && n.contents.push("生成".concat(n.weapp, "个小程序")), n.contents = n.contents.map(function(e) {
            for (var n, t = /\$\{(.+?)\}/g, r = 0, s = []; n = t.exec(e); ) s.push({
                val: e.slice(r, n.index)
            }), r = n.index + n[0].length, s.push({
                style: "color: #50c74e;",
                val: n[1]
            });
            return r < e.length && s.push({
                val: e.slice(r, e.length)
            }), s;
        });
    });
}

function getVer(n) {
    var e = versions.find(function(e) {
        return e.code === +n;
    });
    if (e) return e;
    throw new Error("不存在的version：".concat(n));
}

function getName(e) {
    try {
        return getVer(e).name;
    } catch (e) {
        return "未识别的版本";
    }
}

function getRenewVersions(e) {
    try {
        var n = getVer(e), t = [ n.code ];
        return n.upgrade && n.upgrade.forEach(function(e) {
            var n = getRenewVersions(e);
            t = t.concat(n);
        }), t;
    } catch (e) {
        return [];
    }
}

function getVersions(e) {
    if (e) {
        var n = getRenewVersions(e);
        return versions.filter(function(e) {
            return n.includes(e.code);
        });
    }
    return versions;
}

wx.request({
    url: "https://oss.ibos.cn/common/json/site/versionsv3.json?timestamp=".concat(Date.now()),
    success: function(e) {
        var n = e.data;
        n.versions.filter(function(e) {
            return !e.suspended;
        }).forEach(function(e) {
            return versions.push(e);
        }), setUpContents(versions, n.modelContents);
    },
    fail: console.error
});